package com.yxw.live_vod_boot.service.impl;

import com.alibaba.nacos.shaded.com.google.common.collect.Lists;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yxw.live_vod_boot.service.LiveRecommendService;
import com.yxw.live_vod_boot.entity.YxFollowEntity;
import com.yxw.live_vod_facade.constant.LiveShopConstant;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import com.yxw.live_vod_boot.entity.YxLiveUserWatchDurationEntity;
import com.yxw.live_vod_boot.mapper.FollowMapper;
import com.yxw.live_vod_boot.mapper.OrderMapper;
import com.yxw.live_vod_boot.mapper.ShareMapper;
import com.yxw.live_vod_boot.mapper.YxLiveUserWatchDurationMapper;
import com.yxw.live_vod_boot.vo.LiveOnlineInRedisCacheVO;
import com.yxw.live_vod_boot.utils.RedisManager;
import com.yxw.live_vod_boot.utils.RedisPipeAccessObject;
import java.util.ArrayList;
import java.util.List;
import java.util.Collection;
import java.util.LinkedHashMap;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yxw.live_vod_boot.entity.YxLiveActivityProductsEntity;
import java.util.HashMap;
import java.util.Set;
import com.yxw.live_vod_facade.vo.LiveActivityProductsVO;

/**
 * 直播推荐服务
 * @author jiaxu.huang
 * @date 2023-12-24
 */

@Slf4j
@Service
public class LiveRecommendServiceImpl implements LiveRecommendService{
    private static final long USER_CACHE_EXIST_TIME = 14400;
    @Resource
    private RedisTemplate redisTemplate;
    @Resource
    private RedisManager oRedisManager;
    @Autowired
    private FollowMapper oFollowMapper;    
    @Autowired
    private OrderMapper oOrderMapper;
    @Autowired
    private ShareMapper oShareMapper;
    @Autowired
    private YxLiveUserWatchDurationMapper oYxLiveUserWatchDurationMapper;
    
    @Override
    public BaseResult liveUserCacheInit(Long userId)
    {
        long expireTime = getExpireTime();//System.currentTimeMillis()/1000 + USER_CACHE_EXIST_TIME;
        ArrayList<RedisPipeAccessObject> pipeList = new ArrayList();
        String redisKey;
        RedisPipeAccessObject oRedisPipeAccessObject;
 
        //已经看过的直播
        redisKey = LiveShopConstant.LIVE_SHOP_USER_WATCHED_LIVEHASH_REDISKEY_PREFIX.concat(userId.toString());
        if(oRedisManager.exsist(redisKey))
        {
            oRedisPipeAccessObject = RedisPipeAccessObject.getExpireObject(redisKey, expireTime);
            pipeList.add(oRedisPipeAccessObject);            
        }
        //关注过的店铺
        redisKey = LiveShopConstant.LIVE_SHOP_USER_FOLLOW_SHOP_HASHMAP_PREFIX.concat(userId.toString());

        HashMap oUserFollowConcurrentHashMap = new HashMap();
        if(!oRedisManager.exsist(redisKey))
        {           
            LambdaQueryWrapper<YxFollowEntity> oYxFollowQueryWrapper = new LambdaQueryWrapper();
            oYxFollowQueryWrapper.eq(YxFollowEntity::getFollowerId, userId);
            oYxFollowQueryWrapper.eq(YxFollowEntity::getFollowerType, 1);
            oYxFollowQueryWrapper.eq(YxFollowEntity::getFolloweeType, 0);
            oYxFollowQueryWrapper.eq(YxFollowEntity::getFollowStatus, 0);
            oYxFollowQueryWrapper.eq(YxFollowEntity::getFollowScene, 1);
            List<YxFollowEntity> followList = oFollowMapper.selectList(oYxFollowQueryWrapper);
            if(!followList.isEmpty())
            {
                for(YxFollowEntity oYxFollowEntity : followList)
                {
                    //UserFollowShopCacheVO oUserFollowShopCacheVO = new UserFollowShopCacheVO();
                    //oUserFollowShopCacheVO.setLiveShopId(oYxFollowEntity.getFolloweeShopId());
                    //oUserFollowShopCacheVO.setUserId(userId);
                    oUserFollowConcurrentHashMap.put(oYxFollowEntity.getFolloweeShopId().toString(), oYxFollowEntity.getFolloweeShopId().toString());
                }
            }
            oRedisPipeAccessObject = RedisPipeAccessObject.getAddMapObject(redisKey, oUserFollowConcurrentHashMap, expireTime);
            pipeList.add(oRedisPipeAccessObject);            
        }
        else
        {
            oRedisPipeAccessObject = RedisPipeAccessObject.getExpireObject(redisKey, expireTime);
            pipeList.add(oRedisPipeAccessObject);
        }
        //购买过商品的直播间(有订单的商铺)
        redisKey = LiveShopConstant.LIVE_SHOP_USER_ORDER_SHOP_HASHMAP_PREFIX.concat(userId.toString());
        HashMap oUserOrderShopConcurrentHashMap = new HashMap();
        if(!oRedisManager.exsist(redisKey))
        {  
            List<Long> shopIdList = oOrderMapper.getShopIdsByUserId(userId);
            if(!shopIdList.isEmpty())
            {
                for(Long tmp : shopIdList)
                {
                    oUserOrderShopConcurrentHashMap.put(tmp.toString(), tmp.toString());
                }
            }
            oRedisPipeAccessObject = RedisPipeAccessObject.getAddMapObject(redisKey, oUserOrderShopConcurrentHashMap, expireTime);
            pipeList.add(oRedisPipeAccessObject);            
        }
        else
        {
            oRedisPipeAccessObject = RedisPipeAccessObject.getExpireObject(redisKey, expireTime);
            pipeList.add(oRedisPipeAccessObject);
        }
        //用户分享过的直播间
        redisKey = LiveShopConstant.LIVE_SHOP_USER_SHARE_HASHMAP_PREFIX.concat(userId.toString());
        if(!oRedisManager.exsist(redisKey))
        {  
            HashMap oUserShareConcurrentHashMap = new HashMap();
            List<Long> liveShopIdList = oShareMapper.getLiveShopIdsByUserId(userId);
            if(!liveShopIdList.isEmpty())
            {
                for(Long tmp : liveShopIdList)
                {
                    oUserShareConcurrentHashMap.put(tmp.toString(), tmp.toString());
                }
            }
            oRedisPipeAccessObject = RedisPipeAccessObject.getAddMapObject(redisKey, oUserShareConcurrentHashMap, expireTime);
            pipeList.add(oRedisPipeAccessObject);
        }
        else
        {
            oRedisPipeAccessObject = RedisPipeAccessObject.getExpireObject(redisKey, expireTime);
            pipeList.add(oRedisPipeAccessObject);
        } 
        //用户观看时长超过20分钟的店铺
        redisKey = LiveShopConstant.LIVE_SHOP_USER_WATCHDURATION_HASHMAP_PREFIX.concat(userId.toString());
        if(!oRedisManager.exsist(redisKey))
        {
            LambdaQueryWrapper<YxLiveUserWatchDurationEntity> oUserWatchDurationQueryWrapper = new LambdaQueryWrapper();
            oUserWatchDurationQueryWrapper.eq(YxLiveUserWatchDurationEntity::getUserInnerId, userId);
            List<YxLiveUserWatchDurationEntity> oWatchDurationList = oYxLiveUserWatchDurationMapper.selectList(oUserWatchDurationQueryWrapper);
            if(!oWatchDurationList.isEmpty())
            {
                HashMap oWatchDurationConcurrentHashMap = new HashMap();
                for(YxLiveUserWatchDurationEntity oYxLiveUserWatchDurationEntity : oWatchDurationList)
                {
                    oWatchDurationConcurrentHashMap.put(oYxLiveUserWatchDurationEntity.getLiveShopId().toString(), oYxLiveUserWatchDurationEntity.getLiveShopId().toString());
                }
                oRedisPipeAccessObject = RedisPipeAccessObject.getAddMapObject(redisKey, oWatchDurationConcurrentHashMap, expireTime);
                pipeList.add(oRedisPipeAccessObject);
            }
        }
        else
        {
            oRedisPipeAccessObject = RedisPipeAccessObject.getExpireObject(redisKey, expireTime);
            pipeList.add(oRedisPipeAccessObject);
        }
        oRedisManager.multiAccessByPipe(pipeList);
        return BaseResult.success();
    }
    @Override
    public BaseResult liveUserGetOneLiveRecommend(Long userId)
    {
        LiveOnlineInRedisCacheVO oReturnLiveOnlineInRedisCacheVO = null;
        List<LiveOnlineInRedisCacheVO> oWatchedListAll = new ArrayList();
        LinkedHashMap  oWatchedLinkedHashMap = (LinkedHashMap)oRedisManager.getMap(LiveShopConstant.LIVE_SHOP_USER_WATCHED_LIVEHASH_REDISKEY_PREFIX.concat(":" + userId.toString())); 
        if(!oWatchedLinkedHashMap.isEmpty()){
            oWatchedListAll = Lists.newArrayList(oWatchedLinkedHashMap.values());
        }
        List<LiveOnlineInRedisCacheVO> likeList = getLikeList(userId,oWatchedListAll);
        if(!likeList.isEmpty()){
            //感兴趣
            oReturnLiveOnlineInRedisCacheVO = likeList.get(0);
        }
        else{
            List<LiveOnlineInRedisCacheVO> watchDurationList = getWatchDurationList(userId,oWatchedListAll);
            if(!likeList.isEmpty()){
                //可能感兴趣
                oReturnLiveOnlineInRedisCacheVO = watchDurationList.get(0);
            }
            else{
                //在线直播
                String redisKey = LiveShopConstant.LIVE_SHOP_ONLINELIVE_HASH_REDISKEY;
                LinkedHashMap  oOnlineLiveLinkedHashMap = (LinkedHashMap)oRedisManager.getMap(redisKey); 
                if(!oOnlineLiveLinkedHashMap.isEmpty()){
                    List<LiveOnlineInRedisCacheVO> listOnlineAll = Lists.newArrayList(oOnlineLiveLinkedHashMap.values());//(List<LiveOnlineInRedisCacheVO>)oOnlineLiveLinkedHashMap.values();
                    listOnlineAll.removeAll(oWatchedListAll);
                    if(!listOnlineAll.isEmpty()){
                        oReturnLiveOnlineInRedisCacheVO = listOnlineAll.get(0);
                    }
                }
            }
        }
        if(null != oReturnLiveOnlineInRedisCacheVO){
            /*
            long expireTime = getExpireTimeX(oReturnLiveOnlineInRedisCacheVO);
            if(expireTime>0){
                String redisKey = LiveShopConstant.LIVE_SHOP_USER_WATCHED_LIVEHASH_REDISKEY_PREFIX.concat(userId.toString());
                oRedisManager.setMapValue(redisKey, oReturnLiveOnlineInRedisCacheVO.getLiveId(), oReturnLiveOnlineInRedisCacheVO);
            }
            */
            return BaseResult.success(oReturnLiveOnlineInRedisCacheVO);
        }
        return BaseResult.success("没有更多推荐了");
    }
    /*
    按分页获取直播推荐
    */
    @Override
    public BaseResult liveUserGetLiveRecommendPage(Long currentPage,Long pageSize,Long userId)
    {
        if(currentPage<1){
            currentPage = 1L;
        }
        if(pageSize<1){
            pageSize = 1L;
        }        
        //List<LiveOnlineInRedisCacheVO> oReturnList = null;//new ArrayList();
        System.out.println("userId:" + userId);
        Page oReturnPage =null;
        //观看过的
        System.out.println("开始检查观看过的直播=============================================================");
        System.out.println("oWatchedLinkedHashMap  Key:" + LiveShopConstant.LIVE_SHOP_USER_WATCHED_LIVEHASH_REDISKEY_PREFIX.concat(userId.toString()));
        List<LiveOnlineInRedisCacheVO> oWatchedListAll = new ArrayList();
        LinkedHashMap  oWatchedLinkedHashMap = (LinkedHashMap)oRedisManager.getMap(LiveShopConstant.LIVE_SHOP_USER_WATCHED_LIVEHASH_REDISKEY_PREFIX.concat(userId.toString())); 
        if(!oWatchedLinkedHashMap.isEmpty()){
            oWatchedListAll = Lists.newArrayList(oWatchedLinkedHashMap.values());
        }
        
        if(!oWatchedListAll.isEmpty())
        {
            System.out.println("观看过的 oWatchedListAll:");
            System.out.println(oWatchedListAll);
            System.out.println("============================================");
            for(LiveOnlineInRedisCacheVO oLiveOnlineInRedisCacheVO : oWatchedListAll)
            {                
                System.out.println(oLiveOnlineInRedisCacheVO);
            }       
        }           
        System.out.println("开始检查感兴趣的直播=============================================================");
        List<LiveOnlineInRedisCacheVO> likeList = getLikeList(userId,oWatchedListAll);
        Page likePage;
        if(!likeList.isEmpty()){
            System.out.println("likeList.size():" + likeList.size());
            System.out.println("感兴趣likeList:");
            for(LiveOnlineInRedisCacheVO oLiveOnlineInRedisCacheVO : likeList)
            {   
                if(null == oLiveOnlineInRedisCacheVO)
                {
                    //likeList.remove(oLiveOnlineInRedisCacheVO);
                }
                System.out.println(oLiveOnlineInRedisCacheVO);
            }   
            //感兴趣
            likePage = getPageFromList(currentPage,pageSize,likeList);
            if(likePage.getRecords().size() == pageSize.intValue()){  
                oReturnPage = likePage;
                List<LiveOnlineInRedisCacheVO> watchedLives = oReturnPage.getRecords();
                saveWatchedToRedis(watchedLives,userId);
                System.out.println("return 1 entry");
                return BaseResult.success(oReturnPage);
            }
        }
        else
        {
            likeList = new ArrayList();
        }
        
        if(!likeList.isEmpty())
        {
            System.out.println("likeList:oLiveOnlineInRedisCacheVO:");
            for(LiveOnlineInRedisCacheVO oLiveOnlineInRedisCacheVO : likeList)
            { 
                if(null == oLiveOnlineInRedisCacheVO)
                {
                    //likeList.remove(oLiveOnlineInRedisCacheVO);
                }
                System.out.println(oLiveOnlineInRedisCacheVO);
            }            
        }
        System.out.println("开始检查可能感兴趣的直播=============================================================");
        //if(null == oReturnPage)
        //{
            //可能感兴趣
            List<LiveOnlineInRedisCacheVO> watchDurationList = getWatchDurationList(userId,oWatchedListAll);
            if(!watchDurationList.isEmpty()){
                System.out.println("可能感兴趣 watchDurationList:");
                for(LiveOnlineInRedisCacheVO oLiveOnlineInRedisCacheVO : watchDurationList)
                {                
                    System.out.println(oLiveOnlineInRedisCacheVO);
                }             
                //先去除重合的部分  需要加上没满分页的感兴趣的集合
                if(!likeList.isEmpty()){
                    watchDurationList.removeAll(likeList);
                }                
                //if(!watchDurationList.isEmpty()){
                    likeList.addAll(watchDurationList);
                    if(!likeList.isEmpty()){
                        for(LiveOnlineInRedisCacheVO oLiveOnlineInRedisCacheVO : likeList)
                        {                
                            System.out.println(oLiveOnlineInRedisCacheVO);
                        }                    
                        Page watchDurationPage = getPageFromList(currentPage,pageSize,likeList);
                        if(watchDurationPage.getRecords().size() == pageSize.intValue()){
                            oReturnPage = watchDurationPage;
                            List<LiveOnlineInRedisCacheVO> watchedLives = oReturnPage.getRecords();
                            saveWatchedToRedis(watchedLives,userId);
                            System.out.println("return 2 entry");
                            return BaseResult.success(oReturnPage);                            
                        }
                    }
                //}
            }            
        //}
        System.out.println("开始检查在线直播=============================================================");
        if(null == likeList)
        {
            likeList = new ArrayList();
        }
        if(likeList.isEmpty())
        {
            likeList = new ArrayList();
        }
        //if(null == oReturnPage){
            //在线直播
            LinkedHashMap oOnlineLiveLinkedHashMap = (LinkedHashMap)oRedisManager.getMap(LiveShopConstant.LIVE_SHOP_ONLINELIVE_HASH_REDISKEY); 
            if(!oOnlineLiveLinkedHashMap.isEmpty()){
                List<LiveOnlineInRedisCacheVO> listOnlineAll = Lists.newArrayList(oOnlineLiveLinkedHashMap.values());//(List<LiveOnlineInRedisCacheVO>)oOnlineLiveLinkedHashMap.values();
                System.out.println("在线直播 listOnlineAll:");
                for(LiveOnlineInRedisCacheVO oLiveOnlineInRedisCacheVO : listOnlineAll)
                {                
                    System.out.println(oLiveOnlineInRedisCacheVO);
                }                  
                if(!oWatchedListAll.isEmpty()){
                     System.out.println("去除观看过的直播");
                    listOnlineAll.removeAll(oWatchedListAll);
                }
                System.out.println("listOnlineAll去除观看后的" + listOnlineAll.size());
                if(!listOnlineAll.isEmpty())
                {
                    if(!likeList.isEmpty()){
                        System.out.println("likeList:");
                        for(LiveOnlineInRedisCacheVO oLiveOnlineInRedisCacheVO : likeList)
                        {                
                            System.out.println(oLiveOnlineInRedisCacheVO);
                        }  
                        listOnlineAll.removeAll(likeList);
                    }
                    System.out.println("喜欢的list" + likeList.size());
                    System.out.println("listOnlineAll去除喜欢的list" + listOnlineAll.size());
                    //if(!listOnlineAll.isEmpty()){
                        likeList.addAll(listOnlineAll);
                        for(LiveOnlineInRedisCacheVO oLiveOnlineInRedisCacheVO : likeList)
                        {                
                            System.out.println(oLiveOnlineInRedisCacheVO);
                        } 
                        System.out.println("喜欢的list加上在线的list" + likeList.size());
                        oReturnPage = getPageFromList(currentPage,pageSize,likeList);
                        List<LiveOnlineInRedisCacheVO> watchedLives = oReturnPage.getRecords();
                        System.out.println("watchedLives" + watchedLives.size());
                        saveWatchedToRedis(watchedLives,userId);
                        System.out.println("return 3 entry");
                        return BaseResult.success(oReturnPage);
                    //}
                }
                else
                {
                    System.out.println("在线直播为空=============================================================oOnlineLiveLinkedHashMap.isEmpty()");
                }
            }
            else
            {
                System.out.println("在线直播为空=============================================================oOnlineLiveLinkedHashMap.isEmpty()");
            }
        //}
        return BaseResult.successWithMsg("没有更多推荐了");
    }
    /*** 
    * 根据直播Id获取小黄车的商品 
    * @param liveShopId
    * @return List<YxLiveActivityProductsEntity>
    **/
    @Override
    public BaseResult liveActivityProductsGetOnlineList(String liveId)
    {
        LinkedHashMap oOnlineProductLinkedHashMap = (LinkedHashMap)oRedisManager.getMap(LiveShopConstant.LIVE_SHOP_PRODUCT_REDISKEY_PREFIX.concat(liveId)); 
        if(!oOnlineProductLinkedHashMap.isEmpty()){
            List<LiveActivityProductsVO> listOnlineAll = Lists.newArrayList(oOnlineProductLinkedHashMap.values());
            return BaseResult.success(listOnlineAll);
        }
        return BaseResult.failed("小黄车内还没有商品");
    }    
    private void saveWatchedToRedis(List<LiveOnlineInRedisCacheVO> watchedLives,Long userId)
    {
        List<RedisPipeAccessObject> pipeList =  new ArrayList();
        for(LiveOnlineInRedisCacheVO oTmp : watchedLives){
            if(null != oTmp){

                //long expireTime = getExpireTimeX(oTmp);
                RedisPipeAccessObject oRedisPipeAccessObject;
                //if(expireTime > 0){
                    //oRedisPipeAccessObject = RedisPipeAccessObject.getAddObject(LiveShopConstant.LIVE_SHOP_USER_WATCHED_LIVEHASH_REDISKEY_PREFIX.concat(userId.toString()).concat(":" + oTmp.getLiveId()), oTmp, expireTime);
                    oRedisPipeAccessObject = RedisPipeAccessObject.getAddMapValueObject(LiveShopConstant.LIVE_SHOP_USER_WATCHED_LIVEHASH_REDISKEY_PREFIX.concat(userId.toString()), oTmp.getLiveId(), oTmp);
                    pipeList.add(oRedisPipeAccessObject);
                //}
            }           
        }
        if(!pipeList.isEmpty()){
            //oRedisManager.multiAccessByPipe(pipeList);
        }    
    }
    private List<LiveOnlineInRedisCacheVO> getPageList(Long currPage,Long pageSize,List<LiveOnlineInRedisCacheVO> listAll)
    {
        if(listAll.isEmpty())
        {
            return listAll;
        }
        if(pageSize < 1L)
        {
            pageSize = 1L;
        }
        if(currPage < 1L)
        {
            currPage = 1L;
        }        
        Long size = Long.valueOf(listAll.size());
        if(size == 0L)
        {
            return listAll;
        }        
        Long pages = (size%pageSize) == 0L ? size/pageSize: size/pageSize + 1L;
        if(currPage > pages)
        {
            currPage = pages;
        }

        Long start = (currPage - 1) * pageSize;
        Long end;
        if(currPage.equals(pages))
        {
            end = size - 1;
        }
        else
        {
            end = start + pageSize - 1;
        }
        return listAll.subList(start.intValue(), end.intValue());
    } 
    public <T> Page<T> getPageFromList(Long currPage,Long pageSize,List<LiveOnlineInRedisCacheVO> listAll)
    {
        if(pageSize < 1L)
        {
            pageSize = 1L;
        }
        if(currPage < 1L)
        {
            currPage = 1L;
        }
        Page<T> pageParams = new Page<>(currPage,pageSize);
        Long size = Long.valueOf(listAll.size());
        if(size == 0L)
        {
            pageParams.setTotal(0);
            return pageParams;
        }        
        Long pages = (size%pageSize) == 0L ? size/pageSize: size/pageSize + 1L;
        if(currPage > pages)
        {
            currPage = pages;
        }
        pageParams.setTotal(size);
        pageParams.setCurrent(currPage);
        Long start = (currPage - 1) * pageSize;
        Long end;
        if(currPage.equals(pages))
        {
            end = size - 1;
        }
        else
        {
            end = start + pageSize - 1;
        }
        if(end < 1)
        {
            end = 1L;
        }
        listAll.subList(start.intValue(), end.intValue());
        pageParams.setRecords((List<T>)listAll.subList(start.intValue(), end.intValue()));
        return pageParams;
    }
    
    //感兴趣结果集
    public List<LiveOnlineInRedisCacheVO> getLikeList(Long userId,List<LiveOnlineInRedisCacheVO> oWatchedList)
    {
         //关注过的店铺
        String redisKey = LiveShopConstant.LIVE_SHOP_USER_FOLLOW_SHOP_HASHMAP_PREFIX.concat(userId.toString());

        LinkedHashMap oUserFollowLinkedHashMap = (LinkedHashMap)oRedisManager.getMap(redisKey);
        if(oUserFollowLinkedHashMap.isEmpty())
        {           
                oUserFollowLinkedHashMap = new LinkedHashMap();
        }
        //购买过商品的直播间(有订单的商铺)
        redisKey = LiveShopConstant.LIVE_SHOP_USER_ORDER_SHOP_HASHMAP_PREFIX.concat(userId.toString());
        LinkedHashMap oUserOrderShopLinkedHashMap = (LinkedHashMap)oRedisManager.getMap(redisKey);
        if(!oUserOrderShopLinkedHashMap.isEmpty())
        {  
           oUserFollowLinkedHashMap.putAll(oUserOrderShopLinkedHashMap);
        }       
        //用户分享过的直播间(有订单的商铺)
        redisKey = LiveShopConstant.LIVE_SHOP_USER_SHARE_HASHMAP_PREFIX.concat(userId.toString());
        LinkedHashMap oUserShareLinkedHashMap = (LinkedHashMap)oRedisManager.getMap(redisKey);
        if(!oUserShareLinkedHashMap.isEmpty())
        {  
           oUserFollowLinkedHashMap.putAll(oUserShareLinkedHashMap);
        }
        List<LiveOnlineInRedisCacheVO> oNeedArrayList = new ArrayList();
       
        if(!oUserFollowLinkedHashMap.isEmpty())
        {
            System.out.println("oUserFollowLinkedHashMap.values():");
            System.out.println(oUserFollowLinkedHashMap.values());            
            redisKey = LiveShopConstant.LIVE_SHOP_ONLINELIVE_SHOPIDKEY_HASH_REDISKEY; 
            List<String> listHk = Lists.newArrayList(oUserFollowLinkedHashMap.values());
            //oNeedArrayList = oRedisManager.getMultiMapValue(redisKey, listHk);
            List<Object> list = oRedisManager.getMultiMapValue(redisKey, listHk);
            for(Object oObject : list)
            {
                System.out.println("Object:");
                System.out.println(oObject);
                if(null != oObject)
                {
                    LiveOnlineInRedisCacheVO oLiveOnlineInRedisCacheVO = (LiveOnlineInRedisCacheVO)oObject;
                    oNeedArrayList.add(oLiveOnlineInRedisCacheVO);
                }
            }

            if(!oNeedArrayList.isEmpty() && !oWatchedList.isEmpty())
            {
                System.out.println("oNeedArrayList去除观看过的：==============================================");
                oNeedArrayList.removeAll(oWatchedList);
            }
        }
            System.out.println("感兴趣结果集结果：==============================================");
            System.out.println("oNeedArrayList.size():" + oNeedArrayList.size());
            System.out.println("oNeedArrayList:");
            for(LiveOnlineInRedisCacheVO oLiveOnlineInRedisCacheVO : oNeedArrayList)
            {                
                System.out.println(oLiveOnlineInRedisCacheVO);
            } 
                
        return oNeedArrayList;
    }
    //根据观看时长推断出也许感兴趣结果集
    public List<LiveOnlineInRedisCacheVO> getWatchDurationList(Long userId,List<LiveOnlineInRedisCacheVO> oWatchedList)
    {
        //用户观看时长超过20分钟的店铺
        String redisKey = LiveShopConstant.LIVE_SHOP_USER_WATCHDURATION_HASHMAP_PREFIX.concat(userId.toString());
        LinkedHashMap oWatchDurationLinkedHashMap = (LinkedHashMap)oRedisManager.getMap(redisKey);
        if(oWatchDurationLinkedHashMap.isEmpty())
        {           
                oWatchDurationLinkedHashMap = new LinkedHashMap();
        }
        List<LiveOnlineInRedisCacheVO> oNeedArrayList = new ArrayList();
        if(!oWatchDurationLinkedHashMap.isEmpty())
        {
            redisKey = LiveShopConstant.LIVE_SHOP_ONLINELIVE_SHOPIDKEY_HASH_REDISKEY;
            List<String> listHk = Lists.newArrayList(oWatchDurationLinkedHashMap.values());
            //oNeedArrayList = oRedisManager.getMultiMapValue(redisKey, listHk);
            List<Object> list = oRedisManager.getMultiMapValue(redisKey, listHk);
            for(Object oObject : list)
            {
                System.out.println("Object:");
                System.out.println(oObject);
                if(null != oObject)
                {
                    LiveOnlineInRedisCacheVO oLiveOnlineInRedisCacheVO = (LiveOnlineInRedisCacheVO)oObject;
                    oNeedArrayList.add(oLiveOnlineInRedisCacheVO);
                }
            }         
            if(!oNeedArrayList.isEmpty() && !oWatchedList.isEmpty())
            {
                oNeedArrayList.removeAll(oWatchedList);
            }
        }
            System.out.println("likeList.size():" + oNeedArrayList.size());
            System.out.println("oNeedArrayList:");
            for(LiveOnlineInRedisCacheVO oLiveOnlineInRedisCacheVO : oNeedArrayList)
            {                
                System.out.println(oLiveOnlineInRedisCacheVO);
            }        
        return oNeedArrayList;
    } 
    //@PostConstruct
    public void LiveRecommenCacheStart()
    {
        /*
        ArrayList<RedisPipeAccessObject> pipeList = new ArrayList();
        String redisKey = LiveShopConstant.LIVE_SHOP_ONLINELIVE_HASH_REDISKEY;
        Object o = oRedisManager.getMap(redisKey);
        if(null == o)
        {
            ConcurrentHashMap oConcurrentHashMap = new ConcurrentHashMap();
            RedisPipeAccessObject oRedisPipeAccessObject = RedisPipeAccessObject.getAddMapObject(redisKey, oConcurrentHashMap);
            pipeList.add(oRedisPipeAccessObject);
        }
        if(!pipeList.isEmpty())
        {
            oRedisManager.multiAccessByPipe(pipeList);
        }
        */
    } 
    private long getExpireTime()
    {
        long expireTime = System.currentTimeMillis()/1000 + USER_CACHE_EXIST_TIME;
        return expireTime;
    }
    private long getExpireTimeX(LiveOnlineInRedisCacheVO oLiveOnlineInRedisCacheVO)
    {
        long expireTime = System.currentTimeMillis();
        System.out.println("System.currentTimeMillis():" + expireTime);
        System.out.println("oTmp.getLiveEndTime():" + oLiveOnlineInRedisCacheVO.getLiveEndTime());
        expireTime = (oLiveOnlineInRedisCacheVO.getLiveEndTime() - expireTime)/1000;
        System.out.println("expireTime:" + expireTime);
        return expireTime;
    }   
}